package com.itheima.prototype;

public class Main {
    public static void main(String[] args) {
        Product product1 = new Product(1, 100.0) ;
        System.out.println(product1.toString());
        Product product2 = (Product) product1.Clone();      // 需要这个对象的时候不用 new 而是调用 Clone() 方法
        System.out.println(product2.toString());
    }
}

interface Protype {
    public Object Clone() ;
}

class Product implements Protype {

    private Integer id ;
    private Double price ;

    public Integer getId() {
        return id;
    }

    public Double getPrice() {
        return price;
    }

    public Product(Integer id , Double price) {
        this.id = id ;
        this.price = price ;
    }

    @Override
    public Object Clone() {
        Product product = new Product(this.id, this.price) ;
        return product ;
    }

    @Override
    public String toString() {
        return STR."Product{id=\{id}, price=\{price}\{'}'}";
    }
}
